<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\model\Module;
use DB;

class ModuleController extends Controller
{
    /**
     * 显示所有模块
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        
        //获取用户角色信息
        $role_id = session('info')['role_id'];
        $data = DB::select('select m.* from modules as m,authors as a where a.role_id=? and a.a_author=1 and m.m_pid=0 and a.module_id=m.id',[$role_id]);
        //$data = DB::table('modules as m')->leftJoin('authors as a','a.modoule_id','=','m.id')->selectRaw('m.*,group_concat(m.m_path,m.id) as paths')->where('a.role_id',1)->where('a.a_aothor',1)->orderBy('m.id')->orderBy('paths');
        return $data;
    }

    /**
    *通过父类id获取所有权限的子模块
    */
    public function getByPid($id){
        //获取用户角色信息
        $role_id = session('info')['role_id'];
        $res = DB::select('select m.* from modules as m,authors as a where a.role_id=? and a.a_author=1 and m.m_pid=? and a.module_id=m.id',[$role_id,$id]);
        return $res;
    }

    
}
